﻿<UserControl x:Class="SharpGL.WPF.SceneTree.SceneTree"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:SharpGL.WPF"
                    xmlns:apexControls="clr-namespace:Apex.Controls;assembly=Apex"
                    xmlns:sgl="clr-namespace:SharpGL;assembly=SharpGL"
             xmlns:sglSceneGraph="clr-namespace:SharpGL.SceneGraph;assembly=SharpGL.SceneGraph"
                    xmlns:sglCore="clr-namespace:SharpGL.SceneGraph;assembly=SharpGL.SceneGraph"
                    xmlns:sglDesignPrimitives="clr-namespace:SharpGL.SceneGraph.Primitives;assembly=SharpGL.SceneGraph"

    x:Name="sceneTreeControl"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>

            <local:CollectionCountToVisibilityConverter x:Key="CollectionCountToVisibilityConverter" />
            <HierarchicalDataTemplate DataType="{x:Type sglCore:SceneElement}" ItemsSource="{Binding Children}">
                <apexControls:ApexGrid Rows="Auto,Auto,Auto">

                    <!-- The first row of the grid - icon, title and enabled button. -->
                    <apexControls:PaddedGrid Grid.Row="0" Columns="Auto,*,Auto" Padding="2">

                        <Image Grid.Column="0" Width="16"
                            Source="/SharpGL.WPF;component/Resources/Folder_16x16.png" 
                             RenderOptions.BitmapScalingMode="Linear" />
                        <TextBox Grid.Column="1" Text="{Binding Name}" VerticalAlignment="Center" />
                        <CheckBox Grid.Column="2" IsChecked="{Binding IsEnabled}" VerticalAlignment="Center" />
                    </apexControls:PaddedGrid>

                    <!-- The second row of the grid, only shown if we have effects. -->
                    <Expander Grid.Row="1" Visibility="{Binding Effects,
                        Converter={StaticResource CollectionCountToVisibilityConverter}}">
                        <Expander.Header>
                            <TextBlock FontWeight="SemiBold" Text="Effects" />
                        </Expander.Header>
                        <Expander.Content>
                            <ItemsControl ItemsSource="{Binding Effects}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Name}" />
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </Expander.Content>
                    </Expander>

                </apexControls:ApexGrid>
                
            </HierarchicalDataTemplate>

        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <TreeView ItemsSource="{Binding Scene.SceneContainer.Children, 
            ElementName=sceneTreeControl}" />
            
    </Grid>
</UserControl>
